﻿#include "zz.h"

#if defined(__QG_H__)

//#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")

using namespace tpl;

int main(void)
{
	k_setlv(KLV_ALL);
	k_mesg("test \n");

	qgRdh* rdh = qgRdh::New("", 640, 480, QGSDF_LAYOUT, "test");

	if (rdh)
	{
		qgStub* stub = rdh->GetStub();

		qgFreeType* font = qgFreeType::New();

		// 위젯
		qgWgs* wg = qgWgs::New();
		qwCtrl* c;

		// 라벨
		c = wg->AddLabel(99, 10, 40, 150, 30, "\xEB\x9D\xBC\xEB\xB2\xA8");
		c->SetTextAlign(QGWALIGN_LEFT | QGWALIGN_VCENTER);
		c->SetBorderMode(true);

		// 버튼
		c = wg->AddButton(0, 10, 100, 150, 30, "BUTTON!!");
		c->SetBorderMode(true);

		// 콤보
		c = wg->AddCombo(0, 450, 10, 150, 30, 160);
		c->SetBorderMode(true);
		//c->SetTextSize(12);
		((qwCombo*)c)->SetAutoHeight(true);
		for (kint i = 0; i < 50; i++)
		{
			char sz[260];
			k_snprintf(sz, 259, "\xEC\xBD\xA4\xEB\xB3\xB4%d", i);
			((qwCombo*)c)->AddItem(sz);
		}

		// 리스트
		c = wg->AddList(0, 420, 50, 200, 250);
		c->SetBorderMode(true);
		//c->SetTextSize(10);
		for (kint i = 0; i < 80; i++)
		{
			char sz[260];
			k_snprintf(sz, 259, "\xEC\x95\x84\xEC\x9D\xB4\xED\x85\x9C %d", i);
			((qwList*)c)->AddItem(sz);
		}

		// 한줄 텍스트
		c = wg->AddLabel(0, 10, 150, 50, 30, "\xED\x95\x9C\xEC\xA4\x84: ");
		c->SetTextAlign(QGWALIGN_RIGHT | QGWALIGN_VCENTER);

		c = wg->AddTextLine(0, 70, 150, 280, 30);
		//c->SetBorderMode(true);

		// 패널
		qwPanel* p = (qwPanel*)wg->AddPanel(0, 10, 250, 350, 150);
		p->SetBorderMode(true);

		K_STMT_BEGIN{
			// 라벨
			c = p->AddLabel(0, 0, 0, 150, 30, "Panel label");
			c->SetTextAlign(QGWALIGN_LEFT | QGWALIGN_TOP);
		}K_STMT_END;

		// 폼
		qwForm* f = (qwForm*)wg->AddForm(0, 50, 50, 300, 300, "\xED\x8F\xBC \xEC\x9C\x88\xEB\x8F\x84\xEC\x9A\xB0");

		K_STMT_BEGIN{
			// 라벨
			c = f->AddLabel(0, 0, 0, 100, 30, "Form label");
			c->SetTextAlign(QGWALIGN_LEFT | QGWALIGN_TOP);

			// 한줄 텍스트
			c = f->AddTextLine(0, 0, 30, 100, 30, "form text line");

			// 콤보
			c = f->AddCombo(0, 110, 0, 160, 30, 160);
			c->SetBorderMode(true);
			c->SetTextSize(12);
			((qwCombo*)c)->SetAutoHeight(true);
			for (kint i = 0; i < 10; i++)
			{
				char sz[260];
				k_snprintf(sz, 259, "combo#%d", i);
				((qwCombo*)c)->AddItem(sz);
			}

			// 목록
			c = f->AddList(0, 110, 40, 160, 200);
			c->SetBorderMode(true);
			c->SetTextSize(12);
			for (kint i = 0; i < 30; i++)
			{
				char sz[260];
				k_snprintf(sz, 259, "list#%d", i);
				((qwList*)c)->AddItem(sz);
			}
		}K_STMT_END;

		//
		while (rdh->Run())
		{
			float adv = stub->GetAdvance();

			// 찾기 테스트
			c = wg->FindControl(99);
			if (c)
			{
				char sz[260];
				k_snprintf(sz, 260 - 1, "KEY: %c%c%c",
					stub->IsKeyDown(QIK_ALT) ? 'C' : '-',
					stub->IsKeyDown(QIK_LALT) ? 'L' : '-',
					stub->IsKeyDown(QIK_RALT) ? 'R' : '-');
				c->SetText(sz);
			}

			//
			rdh->Enter();

			wg->Update(adv);
			wg->Draw();

			font->WriteFormat(5, 5, 0, "[%.2f]", stub->GetRunFps());

			rdh->Leave();
			rdh->Flush();
		}

		wg->Unload();
		font->Unload();

		rdh->Unload();
	}

	return 0;
}

#endif
